package com.xiaoshangkou.smalltv2.thread;

import com.xiaoshangkou.smalltv2.commons.SendmailUtil;
import com.xiaoshangkou.smalltv2.commons.publicList;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class SubThread_TT2 implements Runnable{
    private String ip;

    public SubThread_TT2(String ip) {
        this.ip = ip;
    }

    @Override
    public void run() {
        try {
//            EmailSend.sendText();
            new SendmailUtil("1430235457@qq.com").sendTextEmail("你好");

        } catch (Exception e) {
            e.printStackTrace();
        }
        try(DatagramSocket datagramSocket=new DatagramSocket(9999)){
            while (true){
                if (publicList.flag) {
                    //传输到ESP8266中
                    //创建数据报包对象DatagramPacket对象
                    DatagramPacket datagramPacket=new DatagramPacket(publicList.imagesData,publicList.imagesData.length,new InetSocketAddress(ip,8888));
                    //发送消息
                    datagramSocket.send(datagramPacket);
                    publicList.flag=false;
                }
                //判断是否被中断
                if(Thread.currentThread().isInterrupted()){
                    //处理中断逻辑
                    break;
                }
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
